package fun.coding.leetcode;

public class BestTimeToBuyAndSellStock {

	public static void main(String[] args) {

	}
	
	public int maxProfit(int[] prices) {
		if (prices == null || prices.length <= 1) return 0;
		
		int min = Integer.MAX_VALUE;
		int maxProfit = 0;
		
		for (int i = 0; i < prices.length; i++) {
			if (prices[i] < min) {
				min = prices[i];
			} else {
				maxProfit = Math.max(maxProfit, prices[i] - min);
			}
		}
		return maxProfit;
	}

}
